﻿Imports System.Windows.Forms


Public Class frmAPPY7_BK

    Private m_sAPY7_Caption As String
    ''' <summary>
    ''' Create new database 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWindowToolStripMenuItem.Click
        Dim saveFileDialog As New SaveFileDialog
        saveFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        saveFileDialog.Filter = "Appy7 file (*.db3)|*.db3"
        If (saveFileDialog.ShowDialog(Me) = Windows.Forms.DialogResult.OK) Then
            g_sDbName = saveFileDialog.FileName
            Dim sqliteDb As New SQLiteDatabase(g_sDbName)
            If (sqliteDb.createTable() = False) Then
                MessageBox.Show("Lỗi tạo cơ sở dữ liệu")
            End If
        End If
    End Sub

    Private Sub OpenFile(ByVal sender As Object, ByVal e As EventArgs) Handles OpenToolStripMenuItem.Click, OpenToolStripButton.Click
        Dim OpenFileDialog As New OpenFileDialog
        OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        OpenFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
        If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
            g_sDbName = OpenFileDialog.FileName
            ' TODO: Add code here to open the file.
        End If
    End Sub

    Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SaveAsToolStripMenuItem.Click
        Dim SaveFileDialog As New SaveFileDialog
        SaveFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        SaveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"

        If (SaveFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
            Dim FileName As String = SaveFileDialog.FileName
            ' TODO: Add code here to save the current contents of the form to a file.
        End If
    End Sub


    Private Sub ExitToolsStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub CutToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CutToolStripMenuItem.Click
        ' Use My.Computer.Clipboard to insert the selected text or images into the clipboard
    End Sub

    Private Sub CopyToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CopyToolStripMenuItem.Click
        ' Use My.Computer.Clipboard to insert the selected text or images into the clipboard
    End Sub

    Private Sub PasteToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles PasteToolStripMenuItem.Click
        'Use My.Computer.Clipboard.GetText() or My.Computer.Clipboard.GetData to retrieve information from the clipboard.
    End Sub

    Private Sub ToolBarToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ToolBarToolStripMenuItem.Click
        Me.ToolStrip.Visible = Me.ToolBarToolStripMenuItem.Checked
    End Sub

    Private Sub StatusBarToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles StatusBarToolStripMenuItem.Click
        Me.StatusStrip.Visible = Me.StatusBarToolStripMenuItem.Checked
    End Sub

    Private Sub CascadeToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CascadeToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.Cascade)
    End Sub

    Private Sub TileVerticalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TileVerticalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileVertical)
    End Sub

    Private Sub TileHorizontalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TileHorizontalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileHorizontal)
    End Sub

    Private Sub ArrangeIconsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ArrangeIconsToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.ArrangeIcons)
    End Sub

    Private Sub CloseAllToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CloseAllToolStripMenuItem.Click
        ' Close all child forms of the parent.
        For Each ChildForm As Form In Me.MdiChildren
            ChildForm.Close()
        Next
    End Sub

    Private m_ChildFormNumber As Integer

    Private Sub ReleaseToolbarButtons()
        If tsbCalendar.Checked Then tsbCalendar.Checked = False
        If tsbTasks.Checked Then tsbTasks.Checked = False
        If tsbContacts.Checked Then tsbContacts.Checked = False
        If tsbMemo.Checked Then tsbMemo.Checked = False
        If tsbDiary.Checked Then tsbDiary.Checked = False
        If tsbClassified.Checked Then tsbClassified.Checked = False
        If tsbBudget.Checked Then tsbBudget.Checked = False
        'If tsbHome.Checked Then tsbHome.Checked = False
    End Sub
    Private Sub tsbCalendar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbCalendar.Click
        Dim frm1 As New frmMemo
        ReleaseToolbarButtons()
        tsbCalendar.Checked = True
        ShowChildWindow(frm1)
    End Sub
    Private Sub tsbTasks_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbTasks.Click
        Dim frm1 As New frmTasks
        ReleaseToolbarButtons()
        tsbTasks.Checked = True
        ShowChildWindow(frm1)
    End Sub
    Private Sub ShowChildWindow(ByRef frm As Form)
        Dim frmExisting As Form
        Do Until Me.MdiChildren.GetLength(0) = 0
            frmExisting = Me.MdiChildren(Me.MdiChildren.GetUpperBound(0))
            If frmExisting.Name = frm.Name Then
                'frmExisting.Visible = False
                frmExisting = Nothing
                Exit Sub
            Else
                frmExisting.Close()
                'frmExisting.Visible = False
                frmExisting = Nothing
            End If
        Loop
        'For Each ts In Me.toolb

        'Next
        With frm
            .MdiParent = Me
            .Dock = DockStyle.Fill
            Me.Text = m_sAPY7_Caption & "  -  [" & UCase(.Text) & "]"
            Me.ToolStripLabel1.Text = .Tag & "   "
            .Show()
            If UCase(.Text) <> "APY7" Then
                WindowsMenu.Text = .Text
                WindowsMenu.Visible = True
            End If
        End With
    End Sub

    Private Sub frmAPY7_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        m_sAPY7_Caption = "APY7" & " - v. " & My.Application.Info.Version.ToString
        tsbHome_Click(Nothing, Nothing)
        login()
    End Sub

    Private Sub tsbContacts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbContacts.Click
        Dim frm1 As New frmContacts
        ReleaseToolbarButtons()
        tsbContacts.Checked = True
        ShowChildWindow(frm1)
    End Sub

    Private Sub tsbMemo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbMemo.Click
        Dim frm1 As New frmMemo
        ReleaseToolbarButtons()
        tsbMemo.Checked = True
        ShowChildWindow(frm1)
    End Sub

    Private Sub tsbDiary_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbDiary.Click
        Dim frm1 As New frmDiary
        ReleaseToolbarButtons()
        tsbDiary.Checked = True
        ShowChildWindow(frm1)
    End Sub

    Private Sub tsbClassified_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbClassified.Click
        Dim frm1 As New frmClassified
        ReleaseToolbarButtons()
        tsbClassified.Checked = True
        ShowChildWindow(frm1)
    End Sub

    Private Sub tsbBudget_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbBudget.Click
        Dim frm1 As New frmBudget
        ReleaseToolbarButtons()
        tsbBudget.Checked = True
        ShowChildWindow(frm1)
    End Sub

    Private Sub tsbHome_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim frm1 As New frmSplash
        ReleaseToolbarButtons()
        'tsbHome.Checked = True
        ShowChildWindow(frm1)
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        Dim frm1 As New frmTestDB
        ReleaseToolbarButtons()
        'tsbHome.Checked = True
        ShowChildWindow(frm1)
    End Sub

    Private Sub login()

    End Sub
End Class
